package com.xbongbong.pro.enums.menu.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.MenuTypeEnum;
import com.xbongbong.pro.enums.AccessLinkEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;


/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/1/16 11:02
 * @desrcption 进销存菜单内容
 * @since v1.0
 */
@Getter
public enum JXCMenuEnum {

    /**
     * 进销存菜单枚举
     */
    PURCHASE_MANAGEMENT(XbbRefTypeEnum.PURCHASE_MANAGEMENT.getName(), XbbRefTypeEnum.PURCHASE_MANAGEMENT.getAlias(), XbbRefTypeEnum.PURCHASE_MANAGEMENT.getCode(),
            AccessLinkEnum.PURCHASE_MANAGEMENT, "", MenuTypeEnum.GROUP.getType()),

    SUPPLIER(XbbRefTypeEnum.SUPPLIER.getName(), XbbRefTypeEnum.SUPPLIER.getAlias(), XbbRefTypeEnum.SUPPLIER.getCode(),
            AccessLinkEnum.SUPPLIER, XbbRefTypeEnum.PURCHASE_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),

    SUPPLIER_CONTACT(XbbRefTypeEnum.SUPPLIER_CONTACT.getName(), XbbRefTypeEnum.SUPPLIER_CONTACT.getAlias(), XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(),
            AccessLinkEnum.SUPPLIER_CONTACT, XbbRefTypeEnum.PURCHASE_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),

    SUPPLIER_CUSTOMER_COMMUNICATE(XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getName(), XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getAlias(), XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(),
            AccessLinkEnum.SUPPLIER_CUSTOMER_COMMUNICATE, XbbRefTypeEnum.PURCHASE_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),
    // 以销定购
    WAIT_PURCHASE(XbbRefTypeEnum.WAIT_PURCHASE.getName(), XbbRefTypeEnum.WAIT_PURCHASE.getAlias(), XbbRefTypeEnum.WAIT_PURCHASE.getCode(),
            AccessLinkEnum.WAIT_PURCHASE, XbbRefTypeEnum.PURCHASE_MANAGEMENT.getAlias(), MenuTypeEnum.MENU.getType()),
    // 智能补货
    SMART_REPLENISHMENT(XbbRefTypeEnum.SMART_REPLENISHMENT.getName(), XbbRefTypeEnum.SMART_REPLENISHMENT.getAlias(), XbbRefTypeEnum.SMART_REPLENISHMENT.getCode(),
            AccessLinkEnum.SMART_REPLENISHMENT, XbbRefTypeEnum.PURCHASE_MANAGEMENT.getAlias(), MenuTypeEnum.MENU.getType()),
    // 采购合同
    PURCHASE(XbbRefTypeEnum.PURCHASE.getName(), XbbRefTypeEnum.PURCHASE.getAlias(), XbbRefTypeEnum.PURCHASE.getCode(),
            AccessLinkEnum.PURCHASE, XbbRefTypeEnum.PURCHASE_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),
    // 采购退货
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getName(), XbbRefTypeEnum.RETURNED_PURCHASE.getAlias(), XbbRefTypeEnum.RETURNED_PURCHASE.getCode(),
            AccessLinkEnum.RETURNED_PURCHASE,
            XbbRefTypeEnum.PURCHASE_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),

    PRODUCTION_MANAGEMENT(XbbRefTypeEnum.PRODUCTION_MANAGEMENT.getName(), XbbRefTypeEnum.PRODUCTION_MANAGEMENT.getAlias(), XbbRefTypeEnum.PRODUCTION_MANAGEMENT.getCode(),
            AccessLinkEnum.PRODUCTION_MANAGEMENT,
            "", MenuTypeEnum.GROUP.getType()),

    BOM_BILL(XbbRefTypeEnum.BOM_BILL.getName(), XbbRefTypeEnum.BOM_BILL.getAlias(), XbbRefTypeEnum.BOM_BILL.getCode(),
            AccessLinkEnum.BOM_BILL,
            XbbRefTypeEnum.PRODUCTION_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),
    // 模拟生产
    SIMULATED_PRODUCTION(XbbRefTypeEnum.SIMULATED_PRODUCTION.getName(), XbbRefTypeEnum.SIMULATED_PRODUCTION.getAlias(), XbbRefTypeEnum.SIMULATED_PRODUCTION.getCode(),
            AccessLinkEnum.SIMULATED_PRODUCTION,
            XbbRefTypeEnum.PRODUCTION_MANAGEMENT.getAlias(), MenuTypeEnum.MENU.getType()),

    PRODUCTION_ORDER(XbbRefTypeEnum.PRODUCTION_ORDER.getName(), XbbRefTypeEnum.PRODUCTION_ORDER.getAlias(),  XbbRefTypeEnum.PRODUCTION_ORDER.getCode(),
            AccessLinkEnum.PRODUCTION_ORDER,
            XbbRefTypeEnum.PRODUCTION_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),

    INVENTORY_MANAGEMENT(XbbRefTypeEnum.INVENTORY_MANAGEMENT.getName(), XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), XbbRefTypeEnum.INVENTORY_MANAGEMENT.getCode(),
            AccessLinkEnum.INVENTORY_MANAGEMENT,
            "", MenuTypeEnum.GROUP.getType()),
    // 装配出入库单
    ASSEMBLE(XbbRefTypeEnum.ASSEMBLE.getName(), XbbRefTypeEnum.ASSEMBLE.getAlias(), XbbRefTypeEnum.ASSEMBLE.getCode(),
            AccessLinkEnum.ASSEMBLE,
            XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),
    // 盘点单
    INVENTORY(XbbRefTypeEnum.INVENTORY.getName(), XbbRefTypeEnum.INVENTORY.getAlias(), XbbRefTypeEnum.INVENTORY.getCode(),
            AccessLinkEnum.INVENTORY,
            XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),
    // 调拨单
    TRANSFER(XbbRefTypeEnum.TRANSFER.getName(), XbbRefTypeEnum.TRANSFER.getAlias(), XbbRefTypeEnum.TRANSFER.getCode(),
            AccessLinkEnum.TRANSFER, XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),

    // 库存查询
    STOCK_SEARCH(XbbRefTypeEnum.STOCK_SEARCH.getName(), XbbRefTypeEnum.STOCK_SEARCH.getAlias(), XbbRefTypeEnum.STOCK_SEARCH.getCode(),
            AccessLinkEnum.STOCK_SEARCH, XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.MENU.getType()),

    STOCK_FLOW_BILL(XbbRefTypeEnum.STOCK_FLOW_BILL.getName(), XbbRefTypeEnum.STOCK_FLOW_BILL.getAlias(), XbbRefTypeEnum.STOCK_FLOW_BILL.getCode(),
            AccessLinkEnum.STOCK_FLOW_BILL, XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),

    STOCK_STANDING_BOOK(XbbRefTypeEnum.STOCK_STANDING_BOOK.getName(), XbbRefTypeEnum.STOCK_STANDING_BOOK.getAlias(), XbbRefTypeEnum.STOCK_STANDING_BOOK.getCode(),
            AccessLinkEnum.STOCK_STANDING_BOOK, XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(), MenuTypeEnum.FORM.getType()),

    COST_ADJUST(XbbRefTypeEnum.COST_ADJUST.getName(), XbbRefTypeEnum.COST_ADJUST.getAlias(),XbbRefTypeEnum.COST_ADJUST.getCode(),
            AccessLinkEnum.COST_ADJUST,XbbRefTypeEnum.INVENTORY_MANAGEMENT.getAlias(),MenuTypeEnum.FORM.getType()),

    INSTOCK_MANAGEMENT(XbbRefTypeEnum.INSTOCK.getName(), XbbRefTypeEnum.INSTOCK.getAlias(), XbbRefTypeEnum.INSTOCK.getCode(),
            AccessLinkEnum.OTHER_INSTOCK,
            "", MenuTypeEnum.GROUP.getType()),
    // 待入库
    WAIT_INSTOCK(XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getName(), XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getAlias(), XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(),
            AccessLinkEnum.WAIT_INSTOCK_PURCHASE,
            XbbRefTypeEnum.INSTOCK.getAlias(), MenuTypeEnum.MENU.getType()),
    // 采购入库单
    PURCHASE_INSTOCK(XbbRefTypeEnum.PURCHASE_INSTOCK.getName(), XbbRefTypeEnum.PURCHASE_INSTOCK.getAlias(), XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(),
            AccessLinkEnum.PURCHASE_INSTOCK,
            XbbRefTypeEnum.INSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),
    // 销售退货入库
    REFUND_INSTOCK(XbbRefTypeEnum.REFUND_INSTOCK.getName(), XbbRefTypeEnum.REFUND_INSTOCK.getAlias(), XbbRefTypeEnum.REFUND_INSTOCK.getCode(),
            AccessLinkEnum.REFUND_INSTOCK,
            XbbRefTypeEnum.INSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),
    // 其他入库单
    OTHER_INSTOCK(XbbRefTypeEnum.OTHER_INSTOCK.getName(), XbbRefTypeEnum.OTHER_INSTOCK.getAlias(), XbbRefTypeEnum.OTHER_INSTOCK.getCode(),
            AccessLinkEnum.OTHER_INSTOCK,
            XbbRefTypeEnum.INSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),
    //生产入库单
    PRODUCTION_INSTOCK(XbbRefTypeEnum.PRODUCTION_INSTOCK.getName(), XbbRefTypeEnum.PRODUCTION_INSTOCK.getAlias(), XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(),
            AccessLinkEnum.PRODUCTION_INSTOCK,
            XbbRefTypeEnum.INSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),
    //生产退料单
    RETURNED_MATERIEL_INSTOCK(XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getName(), XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getAlias(), XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(),
            AccessLinkEnum.RETURNED_MATERIEL_INSTOCK,
            XbbRefTypeEnum.INSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),

    OUTSTOCK_MANAGEMENT(XbbRefTypeEnum.OUTSTOCK.getName(), XbbRefTypeEnum.OUTSTOCK.getAlias(), XbbRefTypeEnum.OUTSTOCK.getCode(),
            AccessLinkEnum.OTHER_INSTOCK,
            "", MenuTypeEnum.GROUP.getType()),
    // 待出库
    WAIT_OUTSTOCK(XbbRefTypeEnum.WAIT_OUTSTOCK.getName(), XbbRefTypeEnum.WAIT_OUTSTOCK.getAlias(), XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(),
            AccessLinkEnum.WAIT_OUTSTOCK,
            XbbRefTypeEnum.OUTSTOCK.getAlias(), MenuTypeEnum.MENU.getType()),
    // 销售出库单
    CONTRACT_OUTSTOCK(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getName(), XbbRefTypeEnum.CONTRACT_OUTSTOCK.getAlias(), XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(),
            AccessLinkEnum.CONTRACT_OUTSTOCK,
            XbbRefTypeEnum.OUTSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),
    // 采购退货出库单
    RETURNED_PURCHASE_OUTSTOCK(XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getName(), XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getAlias(), XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(),
            AccessLinkEnum.RETURNED_PURCHASE_OUTSTOCK,
            XbbRefTypeEnum.OUTSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),
    // 其他出库单
    OTHER_OUTSTOCK(XbbRefTypeEnum.OTHER_OUTSTOCK.getName(), XbbRefTypeEnum.OTHER_OUTSTOCK.getAlias(), XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(),
            AccessLinkEnum.OTHER_OUTSTOCK,
            XbbRefTypeEnum.OUTSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),

    // 生产领料单
    PRODUCTION_MATERIEL_OUTSTOCK(XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getName(), XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getAlias(), XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(),
            AccessLinkEnum.PRODUCTION_MATERIEL_OUTSTOCK,
            XbbRefTypeEnum.OUTSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),
    // 工单出库单
    WORK_ORDER_OUTSTOCK(XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getName(), XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getAlias(), XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(),
                AccessLinkEnum.WORK_ORDER_OUTSTOCK,
                XbbRefTypeEnum.OUTSTOCK.getAlias(), MenuTypeEnum.FORM.getType()),
    // 仓库
    WAREHOUSE(XbbRefTypeEnum.WAREHOUSE.getName(), XbbRefTypeEnum.WAREHOUSE.getAlias(), XbbRefTypeEnum.WAREHOUSE.getCode(),
            AccessLinkEnum.WAREHOUSE, "", MenuTypeEnum.FORM.getType()),
    ;
    /**
     * saas应用标示解释
     */
    private String name;
    /**
     * saas应用标示
     * @see XbbRefTypeEnum
     */
    private String alias;
    /**
     * @see XbbRefTypeEnum
     */
    private Integer code;
    /**
     * 对应的链接
     */
    private AccessLinkEnum accessLinkEnum;

    /**
     * 父节点，如果没有父节点，则此值为空字符串
     */
    private String parent;
    /**
     * 类型
     * @see MenuTypeEnum
     */
    private Integer type;

    JXCMenuEnum(String name, String alias, Integer code, AccessLinkEnum accessLinkEnum, String parent, Integer type){
        this.name = name;
        this.alias = alias;
        this.code = code;
        this.accessLinkEnum = accessLinkEnum;
        this.parent = parent;
        this.type = type;
    }

    public static JXCMenuEnum getByAlias(String alias) {
        for (JXCMenuEnum jxcMenuEnum: values()) {
            if(jxcMenuEnum.getAlias().equals(alias)) {
                return jxcMenuEnum;
            }
        }
        return null;
    }

    public static JXCMenuEnum getByCode(Integer code) {
        for(JXCMenuEnum jxcMenuEnum: values()) {
            if(jxcMenuEnum.getCode().equals(code)){
                return jxcMenuEnum;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
    /**
     * 获取父级所有的子级
     * @param parentEnum
     * @return
     */
    public static List<JXCMenuEnum> getChildListByParent(JXCMenuEnum parentEnum) {
        List<JXCMenuEnum> list = new ArrayList<>();
        for (JXCMenuEnum cache : values()) {
            boolean flagChild = Objects.equals(cache.parent, parentEnum.getAlias());
            if (flagChild) {
                list.add(cache);
            }
        }
        return list;
    }

    /**
     * 获取所有父级
     * @return
     */
    public static List<JXCMenuEnum> getParentList() {
        List<JXCMenuEnum> list = new ArrayList<>();
        for (JXCMenuEnum cache : values()) {
            boolean flagChild = cache.parent.isEmpty();
            if (flagChild) {
                list.add(cache);
            }
        }
        return list;
    }
}
